/**
 * 报销单打印设置详情
 */
import React, { Component } from 'react';
import { connect } from 'react-redux'
import { messages } from "share/common";
import { Form, Radio, Icon } from 'antd'
import SlideFrameContent from '../slide-frame-content'
import settingService from '../request-and-expense-settings.service'
import 'styles/request-and-expense-settings/expense-setting.scss'

const RadioGroup = Radio.Group;

class ExpensePrintDetail extends Component {

  record = this.props.params.record || {};

  isCopy = this.props.params.isCopy;

  getCompanies = () => {
    let companies = [];
    this.record.companies && this.record.companies.map((id, index) => {
      companies.push({ id, name: this.record.companyNameList[index] })
    });
    return companies;
  };

  priorityInfo = {
    top: (this.props.authPolicyAll || (this.record.expRptPrintOptId && !this.isCopy)) ? 'TENANT' : 'COMPANY',
    disabled: !!this.record.expRptPrintOptId && !this.isCopy,
    value: this.record.expRptPrintOptId ? {
      levelCode: this.record.levelCode,
      levelOrgId: this.record.levelOrgId,
      levelOrgName: this.record.levelOrgName,
      distribution: {
        companies: this.getCompanies()
      }
    } : {
      levelCode: this.props.authPolicyAll ? 'TENANT' : 'COMPANY',
      levelOrgId: this.props.authPolicyAll ? this.props.tenant.id : this.props.company.id,
      levelOrgName: this.props.authPolicyAll ? this.props.tenant.tenantName : this.props.company.name,
    }
  };

  directionOptions = [
    {label: messages('expense-7.key44')/*横向*/, value: false},
    {label: messages('expense-7.key45')/*竖向*/, value: true}
  ];

  printOptions = [
    {label: messages('common.print')/*打印*/, value: true},
    {label: messages('expense-7.key46')/*不打印*/, value: false},
  ];

  numberOptions = [
    {label: messages('expense-7.key47')/*一份*/, value: 1},
    {label: messages('expense-7.key48')/*四份*/, value: 4}
  ];

  controlOptions = [
    {label: messages('expense-7.key49')/*允许*/, value: true},
    {label: messages('expense-7.key50')/*不允许*/, value: false},
  ];

  insteadEnableOptions = [
    {label: messages('expense-7.key51')/*均打印*/, value: 1001},
    {label: messages('expense-7.key52')/*均不打印*/, value: 1002},
    {label: messages('expense-7.key53')/*只打印替票，不打印替票理由*/, value: 1003}
  ];

  formList = [{
    id: 'printDirection',
    label: messages('expense-7.key54')/*报销单打印方向*/,
    extra: messages('expense-7.key55')/*配置报销单打印的列表方向为横向或竖向*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printDirection : false,
    component: <RadioGroup disabled={this.record.readOnly} options={this.directionOptions}/>
  }, {
    id: 'printExpenseSummary',
    label: messages('expense-7.key56')/*费用类型小计*/,
    extra: messages('expense-7.key57')/*配置报销单是否打印“费用类型小计”*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printExpenseSummary : false,
    component: <RadioGroup disabled={this.record.readOnly} options={this.printOptions}/>
  }, {
    id: 'printNoReceipt',
    label: messages('expense-7.key58')/*无票费用（包括第三方费用，滴滴）*/,
    extra: messages('expense-7.key59')/*配置无票费用是否打印（包括第三方费用，滴滴）*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printNoReceipt : true,
    component: <RadioGroup disabled={this.record.readOnly} options={this.printOptions}/>
  }, {
    id: 'printInvoiceComment',
    label: messages('expense-7.key60')/*费用事由说明*/,
    extra: messages('expense-7.key61')/*配置报销单是否打印费用“事由说明”*/,
    initialValue: this.record.expRptPrintOptId && this.record.printInvoiceComment !== undefined ? this.record.printInvoiceComment : true,
    component: <RadioGroup disabled={this.record.readOnly} options={this.printOptions}/>
  }, {
    id: 'printTicketReason',
    label: messages('expense-7.key62')/*替票与替票理由*/,
    extra: messages('expense-7.key63')/*配置开启“替票”功能时，报销单是否打印员工填写的替票理由*/,
    initialValue: this.record.expRptPrintOptId && this.record.printTicketReason ? this.record.printTicketReason : 1001,
    component: <RadioGroup disabled={this.record.readOnly} options={this.insteadEnableOptions}/>
  }, {
    id: 'printOneLineApportion',
    label: messages('expense-7.key64')/*费用只有1行分摊*/,
    extra: messages('expense-7.key65')/*费用只有1行分摊，是否在报销单打印页面显示*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printOneLineApportion : false,
    component: <RadioGroup disabled={this.record.readOnly} options={this.printOptions}/>
  }, {
    id: 'printStepMileage',
    label: messages('expense-7.key66')/*阶梯里程详情*/,
    extra: messages('expense-7.key67')/*当启用阶梯模式里程补贴时，报销单打印里程补贴费用是否显示阶梯里程详情列表*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printStepMileage : false,
    component: <RadioGroup disabled={this.record.readOnly} options={this.printOptions}/>
  }, {
    id: 'printPayment',
    label: messages('expense-7.key68')/*关联银行卡信息和付款信息*/,
    extra: messages('expense-7.key69')/*配置是否打印报销单关联的银行卡信息和付款信息*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printPayment : true,
    component: <RadioGroup disabled={this.record.readOnly} options={this.printOptions}/>
  }, {
    id: 'printHistory',
    label: messages('expense-7.key70')/*审批历史*/,
    extra: messages('expense-7.key71')/*配置是否打印报销单的审批历史*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printHistory : true,
    component: <RadioGroup disabled={this.record.readOnly} options={this.printOptions}/>
  }, {
    id: 'printReceiptNum',
    label: messages('expense-7.key72')/*每页打印发票份数*/,
    extra: messages('expense-7.key73')/*配置报销单打印时每页打印的发票份数*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printReceiptNum : 1,
    component: <RadioGroup disabled={this.record.readOnly} options={this.numberOptions}/>
  }];

  formList2 = [{
    id: 'printAuditBill',
    label: messages('expense-7.key74')/*允许员工打印自己的已审核通过的报销单*/,
    extra: messages('expense-7.key75')/*【我的报销】页面查看自己的已审核通过的报销单详情，是否显示打印按钮*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printAuditBill : true,
    component: <RadioGroup disabled={this.record.readOnly} options={this.controlOptions}/>
  }, {
    id: 'printExpBagBill',
    label: messages('expense-7.key76')/*员工打印关联发票袋的报销单*/,
    extra: messages('expense-7.key77')/*报销单关联发票袋后，是否对员工显示报销单打印按钮*/,
    initialValue: this.record.expRptPrintOptId ? this.record.printExpBagBill : false,
    component: <RadioGroup disabled={this.record.readOnly} options={this.printOptions}/>
  }];

  dealParams = (values) => {
    const { isCopy } = this.props.params;
    !isCopy && (values.expRptPrintOptId = this.record.expRptPrintOptId);
    return values;
  };

  render() {
    let formTitle = (
      <div>
        {messages('expense-7.key78')/*模版内容设置*/}
        {/*<a className="print-setting-view"><Icon type="eye-o"/> 预览打印模版</a>*/}
      </div>
    );
    return (
      <SlideFrameContent
        disabled={this.record.readOnly}
        enabled={this.record.expRptPrintOptId ? this.record.enabled : true}
        priorityInfo={this.priorityInfo}
        formInfo={[
          {title: formTitle, list: this.formList},
          {title: messages('expense-7.key79')/*打印控制与通知*/, list: this.formList2},
        ]}
        service={settingService.updateExpensePrint}
        dealParams={this.dealParams}
        close={this.props.close}
      />
    )
  }

}

function mapStateToProps(state) {
  return {
    authPolicyAll: state.main.authPolicyAll,
    company: state.login.company,
    tenant: state.login.tenant,
  }
}

const WrappedExpensePrintDetail = Form.create()(ExpensePrintDetail);

export default connect(mapStateToProps)(WrappedExpensePrintDetail);
